<template>
  <div>
    <form>
      <div class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          壁挂炉照片(要求正面照片)：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_pic1_path', '壁挂炉照片')"  :src="piece.f_pic1_path" alt="壁挂炉照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_pic1_path', this.piece.f_pic1_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_pic1_path)"></span>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          品牌：</label>
        <div class="col-sm-12">
          <v-select :value.sync="f_brand" :options='brands' placeholder='请选择品牌'
            close-on-select clear-button></v-select>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          出厂日期：</label>
        <div class="col-sm-12">
          <datepicker id="f_making_date" placeholder="出厂日期"
            :value.sync="f_making_date"
            :disabled-days-of-Week="[]"
            :format="'yyyy-MM'"
            :show-reset-button="reset">
          </datepicker>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          工作压力（Pa）：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" maxlength="10" v-model="piece.f_pressure_label">
        </div>
      </div>
      <div>
        <h4>软管</h4>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          安检项</label>
        <div class="col-sm-12">
            <input type="checkbox" v-model="piece.f_pipe_ok">正常</input>
            <input type="checkbox" v-model="piece.f_pipe_leakage">漏气</input>
            <input type="checkbox" v-model="piece.f_pipe_worn">老化</input>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_pipe_worn">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          壁挂炉软管老化照片：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_worn_path', '壁挂炉软管老化照片')"  :src="piece.f_worn_path" alt="壁挂炉软管老化照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_worn_path', this.piece.f_worn_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_worn_path)"></span>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          材质</label>
        <div class="col-sm-12">
          <radio-group :value.sync="piece.f_pipe_material" type="success" buttons="false">
            <radio value="橡胶">橡胶</radio>
            <radio value="铝塑管">铝塑管</radio>
            <radio value="金属管">金属管</radio>
          </radio-group>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_pipe_material == '橡胶'">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          橡胶软管照片：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_material_path', '橡胶软管照片')"  :src="piece.f_material_path" alt="橡胶软管照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_material_path', this.piece.f_material_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_material_path)"></span>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          管卡（个）：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" maxlength="10" v-model="piece.f_pipe_fasten" number>
          <input type="checkbox" v-model="piece.f_pipe_no_fasten">无管卡</input>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_pipe_no_fasten">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          无管卡照片：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_no_fasten_path', '无管卡照片')"  :src="piece.f_no_fasten_path" alt="无管卡照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_no_fasten_path', this.piece.f_no_fasten_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_no_fasten_path)"></span>
        </div>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          长度（米）：</label>
        <div class="col-sm-12">
          <input type="text" class="form-control" maxlength="10" v-model="piece.f_pipe_length2">
        </div>
      </div>
      <div>
        <h4>烟道</h4>
      </div>
      <div :class="paper.style__" class="form-group">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          安检项</label>
        <div class="col-sm-12">
          <input type="checkbox" v-model="piece.f_vent_horizontal">水平</input>
          <input type="checkbox" v-model="piece.f_vent_tilted">倾斜</input>
          <input type="checkbox" v-model="piece.f_vent_balanced">平衡</input>
          <input type="checkbox" v-model="piece.f_vent_forced">强排</input>
          <input type="checkbox" v-model="piece.f_vent_trapped">未接到室外</input>
          <input type="checkbox" v-model="piece.f_vent_damaged">烟道破损</input>
          <input type="checkbox" v-model="piece.f_vent_notsealed">与墙体间未密封</input>
          <input type="checkbox" v-model="piece.f_vent_no">未安装烟道</input>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_damaged">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          烟道破损照片：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_vent_damaged_path', '烟道破损照片')"  :src="piece.f_vent_damaged_path" alt="烟道破损照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_vent_damaged_path', this.piece.f_vent_damaged_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_vent_damaged_path)"></span>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_no">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          未安装烟道照片：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_vent_no_path', '未安装烟道照片')"  :src="piece.f_vent_no_path" alt="未安装烟道照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_vent_no_path', this.piece.f_vent_no_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_vent_no_path)"></span>
        </div>
      </div>
      <div class="form-group" v-show="piece.f_vent_notsealed">
        <label class="col-sm-12 control-label">
          <img src="../../../static/optionright.png" width="25" height="25"></img>&nbsp;
          烟道与墙体间未密封照片：</label>
        <div class="col-sm-12">
          <img :class="paper.style__" @click="takePic('f_vent_notsealed_path', '烟道与墙体间未密封照片')"  :src="piece.f_vent_notsealed_path" alt="烟道与墙体间未密封照片" width="150" height="200">
          &nbsp;&nbsp;&nbsp;&nbsp;<span :class="paper.style__" class="glyphicon glyphicon-trash" @click="delfile('f_vent_notsealed_path', this.piece.f_vent_notsealed_path)"></span>
          &nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-picture" @click="this.$parent.$parent.viewPic(this.piece.f_vent_notsealed_path)"></span>
        </div>
      </div>
    </form>
    <a href="#" class="btn btn-success" @click="goBackValidation">确定</a>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import Vue from 'vue'
import * as Util from '../Util'
import RadioGroup from 'vue-strap/src/radioGroup'
import Radio from 'vue-strap/src/radioBtn'
import Datepicker from 'vue-strap/src/Datepicker'

export default {
  title: '壁挂炉',
  data() {
    return {
      paper: this.$parent.$parent.data,
      brands: Util.choices(this.$parent.$parent.role, '壁挂炉品牌'),
      f_brand: '',
      f_making_date: ''
    }
  },
  props: ['idx'],
  components: {
    RadioGroup,
    Radio,
    Datepicker
  },
  ready() {
    this.$set('piece', this.paper.f_furnaces[this.idx])
    if(!this.piece.f_pic1_path)
      this.$set('piece.f_pic1_path', Vue.nopic)

      if(!this.piece.f_worn_path)
        this.$set('piece.f_worn_path', Vue.nopic)
      this.$watch("piece.f_pipe_worn", function(val){
        if(!val)
          this.$set('piece.f_worn_path', Vue.nopic)
      })
      if(!this.piece.f_no_fasten_path)
        this.$set('piece.f_no_fasten_path', Vue.nopic)
      this.$watch("piece.f_pipe_no_fasten", function(val){
        if(!val) {
          this.$set('piece.f_no_fasten_path', Vue.nopic)
        } else {
          this.$set('piece.f_pipe_fasten', 0)
        }
      })
      if(!this.piece.f_vent_no_path)
        this.$set('piece.f_vent_no_path', Vue.nopic)
      this.$watch("piece.f_vent_no", function(val){
        if(!val)
          this.$set('piece.f_vent_no_path', Vue.nopic)
      })
      if(!this.piece.f_vent_damaged_path)
        this.$set('piece.f_vent_damaged_path', Vue.nopic)
      this.$watch("piece.f_vent_damaged", function(val){
        if(!val)
          this.$set('piece.f_vent_damaged_path', Vue.nopic)
      })
      if(!this.piece.f_vent_notsealed_path)
        this.$set('piece.f_vent_notsealed_path', Vue.nopic)
      this.$watch("piece.f_vent_notsealed", function(val){
        if(!val)
          this.$set('piece.f_vent_notsealed_path', Vue.nopic)
      })
      if(!this.piece.f_material_path)
        this.$set('piece.f_material_path', Vue.nopic)
      this.$watch("piece.f_pipe_material", function(val){
        if(val != '橡胶')
          this.$set('piece.f_material_path', Vue.nopic)
      })

    if(!this.piece.f_making_date) {
      this.$set('piece.f_making_date', null)
    } else {
      this.f_making_date = this.piece.f_making_date
    }
    if(!this.piece.f_brand) {
        this.$set('piece.f_brand', null)
    } else {
      this.f_brand = [this.piece.f_brand]
    }
    this.$watch('f_brand', function (val) {
        this.piece.f_brand = val[0]
    })
    this.$watch('f_making_date', function (val) {
        this.piece.f_making_date = val
    })
  },
  methods: {
    cameraCallBack(prop, fileName) {
      console.log(prop + ',' + fileName)
      HostApp.__this__.piece[prop] = fileName + '?' + Math.random()
      console.log(HostApp.__this__.piece[prop])
      HostApp.__callback__ = null
      HostApp.__this__ = null
    },
    takePic(prop, title) {
      HostApp.__callback__ = this.cameraCallBack
      HostApp.__this__ = this
      console.log('this.piece[prop]:' + this.piece[prop])
      let fileName
      if(!this.piece[prop] || this.piece[prop].includes("nopic.png")) {
        fileName = Util.guid() +'-furnace-' + this.idx + '-' + prop + '.jpg'
      } else {
        fileName = Util.getFileName(this.piece[prop])
      }
      HostApp._open_a_page({type: 'boomerang',
        page: 'com.aofeng.hybrid.android.peripheral.CameraActivity',
        param: {file: fileName, requestCode: 111, callback:'javascript:HostApp.__callback__("' + prop +'", "%s");', watermark: title + '\t时间：'+ Util.toStandardTimeString() + '\t' + Vue.user.name}
      })
    },
    goBackValidation() {
      this.$goto('paper-device', {}, 'paper-router')
    },
    delfile(prop, fileName) {
      if(fileName == Vue.nopic)
        return
      else {
        HostApp.delfile(fileName)
        this.piece[prop] = Vue.nopic
      }
    }
  }
}
</script>
